home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap14 / Bricks3 / BRICKS3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  2.2 KB  |  71 lines

  1. /*-----------------------------------------------
  2.    BRICKS3.C -- CreatePatternBrush Demonstration
  3.                 (c) Charles Petzold, 1998
  4.   -----------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  11.                     PSTR szCmdLine, int iCmdShow)
  12. {
  13.      static TCHAR szAppName [] = TEXT ("Bricks3") ;
  14.      HBITMAP      hBitmap ;
  15.      HBRUSH       hBrush ;
  16.      HWND         hwnd ;
  17.      MSG          msg ;
  18.      WNDCLASS     wndclass ;
  19.  
  20.      hBitmap = LoadBitmap (hInstance, TEXT ("Bricks")) ;
  21.      hBrush = CreatePatternBrush (hBitmap) ;
  22.      DeleteObject (hBitmap) ;
  23.  
  24.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  25.      wndclass.lpfnWndProc   = WndProc ;
  26.      wndclass.cbClsExtra    = 0 ;
  27.      wndclass.cbWndExtra    = 0 ;
  28.      wndclass.hInstance     = hInstance ;
  29.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  30.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  31.      wndclass.hbrBackground = hBrush ; 
  32.      wndclass.lpszMenuName  = NULL ;
  33.      wndclass.lpszClassName = szAppName ;
  34.      
  35.      if (!RegisterClass (&wndclass))
  36.      {
  37.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  38.                       szAppName, MB_ICONERROR) ;
  39.           return 0 ;
  40.      }
  41.      
  42.      hwnd = CreateWindow (szAppName, TEXT ("CreatePatternBrush Demo"), 
  43.                           WS_OVERLAPPEDWINDOW, 
  44.                           CW_USEDEFAULT, CW_USEDEFAULT,
  45.                           CW_USEDEFAULT, CW_USEDEFAULT,
  46.                           NULL, NULL, hInstance, NULL) ;
  47.  
  48.      ShowWindow (hwnd, iCmdShow) ;
  49.      UpdateWindow (hwnd) ;
  50.  
  51.      while (GetMessage (&msg, NULL, 0, 0))
  52.      {
  53.           TranslateMessage (&msg) ;
  54.           DispatchMessage (&msg) ;
  55.      }
  56.  
  57.      DeleteObject (hBrush) ;
  58.      return msg.wParam ;
  59. }
  60.  
  61. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  62. {
  63.      switch (message)
  64.      {
  65.      case WM_DESTROY:
  66.           PostQuitMessage (0) ;
  67.           return 0 ;
  68.      }
  69.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  70. }
  71.